<?
if(!ANTIHACK) die("ANTIHACK...");
include_once(INCLUDES."buildlink.php");
include_once(INCLUDES."split_unicode.php");
$q=query("select * from other where code='title'");
$r=fetch($q);
DEFINE("SITE_TITLE",$r["content1"],true);
DEFINE("SITE_NAME",$r["content2"],true);
DEFINE("SITE_DESCRIPTION",$r["content3"],true);
DEFINE("SITE_KEYWORDS",$r["content4"],true);
DEFINE("SITE_IMAGE","",true);
function getChild($id){
	$q=query("select * from menu where parent='$id'");
	$data[]=$id;
	while($r=fetch($q))
	{
		$arr=getChild($r["id"]);
		$data=array_merge($data, $arr);
	}
	return $data;
}
	$q=query("select * from other where code='box-order'");
	$r=fetch($q);
	$cat=json_decode($r["content1"]);
	for($i=0; $i<count($cat); $i++)
	{
		$listid=getChild($cat[$i]);
		$where=" parent in (".implode(',',$listid).")";
		$q=query("select * from post where $where and is_active=1 order by time desc limit 7");
	//	$q=query("select * from post where is_active=1 order by time desc limit 6");
		$data="";
		while($r=fetch($q))
		{
			$r["time"]= date("H:i m/m/Y",$r["time"]);
			$r["link"]=buildlink("post",$r,"",1);
			$r["image"]=$r["image"]."|".$r["imgwidth"]."|".$r["imgheight"];
			if($i>0 && $i<4)
				$r["described"]=split_unicode($r["described"],130);
			else
				$r["described"]=split_unicode($r["described"],300);
			$data[]=$r;
		}
		$q=query("select * from menu where id=$cat[$i]");
			$r=fetch($q);
			$data[0]["parentName"]=$r["name"];
			$data[0]["parentlink"]=buildlink("menu",$r);
			
		$smarty->assign("data$i",$data);
	}
$hotmusic = query("select * from hot_music");
while($fhotmusic=fetch($hotmusic))
{
	$hot[]=$fhotmusic;
	
}
$smarty->assign("bxh",$hot);
$sel=query("select * from quangcao where position=1 order by sort asc");
$i=0;
while($fsel=fetch($sel))
{
$fsel['count']=$i;
	$getqc=query("select * from link_quangcao where parent=".$fsel['id']);
	$img=array();
	$url=array();
	while($fgetqc=fetch($getqc))
	{
		$img[]=$fgetqc['img'];
		$url[]=baselink.'/clickads.php?id='.$fgetqc['id'].'&url='.$fgetqc['url'];
	}
	$fsel[img]=$img;
	$fsel[url]=$url;
	$qc[]=$fsel;
	$i++;
}
$smarty->assign("quangcao",$qc);
$smarty->display("home.htm");
?>